import {createApp, defineAsyncComponent} from 'vue'

import store from '@/conf/store';
// @ts-ignore
import {authority} from '@/conf/function';
import * as echarts from 'echarts';
import HttpRequest from "@/conf/axios";
// @ts-ignore
import {authority} from "@/conf/functions";
import "echarts-gl";
import 'echarts-liquidfill';

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

declare module '@vue/runtime-core' {
    // noinspection JSUnusedGlobalSymbols
    interface ComponentCustomProperties {
        // @ts-ignore
        $store: store;
        // @ts-ignore
        $axios: HttpRequest;
        // @ts-ignore
        $http: HttpRequest;
        // @ts-ignore
        $authority: authority;
        // @ts-ignore
        $echarts: echarts;
        // @ts-ignore
        $NProgress: NProgress;
    }
}
// @ts-ignore
declare module 'vue/types/vue' {
    // noinspection JSUnusedGlobalSymbols
    interface Vue {
        // @ts-ignore
        $store: store;
        // @ts-ignore
        $axios: HttpRequest;
        // @ts-ignore
        $http: HttpRequest;
        // @ts-ignore
        $authority: authority;
        // @ts-ignore
        $echarts: echarts;
        // @ts-ignore
        $NProgress: NProgress;
    }
}
export default {
    install: function (app: ReturnType<typeof createApp>): void {
        const modules = import.meta.glob("@/components/global/**/*.vue");
        const components = import.meta.globEager("@/components/global/**/*.vue");
        Object.keys(modules).forEach((key: string) => {
            const viewSrc: any = components[key];
            // @ts-ignore
            const file = viewSrc.default;
            // @ts-ignore
            const AsyncComponent: any = defineAsyncComponent(modules[key])
            AsyncComponent.props = file.props;
            app.component(file.name, AsyncComponent)
        });
        const compModules = import.meta.glob("@/views/**/comp/*.vue");
        const compComponents = import.meta.globEager("@/views/**/comp/*.vue");
        Object.keys(compModules).forEach((key: string) => {
            const viewSrc = compComponents[key];
            // @ts-ignore
            const file = viewSrc.default;
            // @ts-ignore
            const AsyncComponent = defineAsyncComponent(compModules[key])
            app.component(file.name, AsyncComponent)
        });
        // @ts-ignore
        app.component("ElIconGrant", "<i class='el-icon-v-grant'></i>")

        app.config.globalProperties.$http = HttpRequest;
        app.config.globalProperties.$authority = authority;
        app.config.globalProperties.$echarts = echarts;
        app.config.globalProperties.$NProgress = NProgress;
    }
}
